package com.rgs.se.concurrent;

import java.util.concurrent.locks.LockSupport;

/**
 * @author Ren Gaoshuai
 * @ClassName Test02_Ticket
 * @Description TODO
 * @date 2021-08-30 9:14
 **/
public class Test02_Ticket implements Runnable{


    private volatile int tickets = 10;

    public void run() {
        while (true){
            if (tickets <= 0){
                break;
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"----->拿到了第"+tickets-- +"张票！");
        }
    }


    public static void main(String[] args) {
        Test02_Ticket ticket = new Test02_Ticket();
        new Thread(ticket,"A").start();
        new Thread(ticket,"B").start();
        new Thread(ticket,"C").start();

     /*   //阻塞线程
        LockSupport.park();
        //唤醒指定的线程
        LockSupport.unpark(new Thread());*/
    }
}
